package com.woniuxy.controller;

import com.woniuxy.entity.ManagerUser;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.servlet.ModelAndView;

import javax.validation.Valid;

@RequestMapping("/UserManager")
@Controller
public class ManagerController {
    @RequestMapping("/addUser")
    public ModelAndView addUser(@Valid @RequestBody ManagerUser managerUser, BindingResult bindingResult){
        ModelAndView modelAndView=new ModelAndView();
        if(bindingResult.hasErrors()){
            FieldError fieldError=bindingResult.getFieldError();
            modelAndView.addObject("binding",fieldError.getField()+""+bindingResult.getFieldError().getDefaultMessage());
        }
        modelAndView.setViewName("/WEB-INF/jsp/error.jsp");
        return modelAndView;
    }
}
